package com.example.saiweisi.controller.userController;

import com.example.saiweisi.common.Result;
import com.example.saiweisi.controller.request.RechargeRequest;
import com.example.saiweisi.model.VipKind;
import com.example.saiweisi.service.interf.IVipCardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

@RequestMapping("/vipcard")
@RestController
@CrossOrigin
@Slf4j
public class VipCardController {
    @Autowired
    IVipCardService vipCardService;

    /**
     * 购买会员卡
     * @param vipKindId 购买的
     * @return
     */
    @PutMapping("/buyvipcard/{vipKindId}/{userId}")
    public Result buyVipCard(@PathVariable Integer vipKindId,@PathVariable Integer userId){
        vipCardService.buyVipCard(userId,vipKindId);
        return Result.success();
    }

    /**
     * 根据用户id获取此用户的会员卡信息
     * @param userId 用户id
     * @return 返回会员信息
     */
    @GetMapping("/getvipcard/{userId}")
    public Result getVipCard(@PathVariable Integer userId){
        return Result.success(vipCardService.getVipCard(userId));
    }

    /**
     * 充值
     * @param rechargeRequest 充值钱数，卡号
     * @return 成功信息
     */
    @PutMapping("/recharge")
    public Result recharge(@RequestBody RechargeRequest rechargeRequest){
       vipCardService.recharge(rechargeRequest);
        return Result.success();
    }

}
